<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="商品名称">
                <a-input v-model="queryParam.keyword" placeholder="请输入商品名称" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button style="margin-right: 8px" @click="resetQueryParams">重置</a-button>
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false">
      <s-table rowKey="id" size="default" :columns="columns" :data="loadData" ref="table"> </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import storage from 'store'
import { STable } from '@/components'
import { sale } from '@/api/statistic/goods'
const columns = [
  {
    title: '商品ID',
    align: 'center',
    dataIndex: 'id',
  },
  {
    title: '商品名称',
    align: 'center',
    dataIndex: 'name',
  },
  {
    title: '浏览量',
    align: 'center',
    dataIndex: 'views',
  },
  {
    title: '加购人数',
    align: 'center',
    dataIndex: 'cart',
  },
  {
    title: '支付人数',
    align: 'center',
    dataIndex: 'paynum',
  },
  {
    title: '商品支付总金额',
    align: 'center',
    dataIndex: 'jine',
  },
]

export default {
  name: 'SaleGoods',
  components: {
    STable,
  },
  data() {
    return {
      labelCol: {
        xs: {
          span: 24,
        },
        sm: {
          span: 5,
        },
      },
      wrapperCol: {
        xs: {
          span: 24,
        },
        sm: {
          span: 16,
        },
      },
      // 表头
      columns,
      modalLoading: false,
      // 查询条件参数
      queryParam: {
        keyword: null,
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        Object.assign(parameter, this.queryParam)
        let params = {
          ...parameter,
          store_id: storage.get('storeId')
        }
        return sale(params)
          .then((res) => {
            console.log('sale', res)
            return res.data
          })
          .catch((err) => {
            this.$message.error(err.message)
            this.$refs.table.localLoading = false
          })
      },
    }
  },
  filters: {},
  created() {},
  methods: {
    resetQueryParams() {
      Object.assign(this.queryParam, {
        keyword: null,
      })
      this.$refs.table.refresh(true)
    },
  },
}
</script>

<style lang="less" scoped>
.permission-form {
  /deep/ .permission-group {
    margin-top: 0;
    margin-bottom: 0;
  }
}
</style>
